package com.community.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.community.dto.MakePurchaseDto;
import com.community.dto.PurchaseOrderDto;
import com.community.pojo.Product;
import com.community.pojo.PurchaseOrder;
import com.community.mapper.PurchaseOrderMapper;
import com.community.service.IPurchaseOrderDetailsService;
import com.community.service.IPurchaseOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import com.community.utils.PageUtils;
import com.community.vo.ProductVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author TangHaoSong Fly ChenJie HeYuHang
 * @since 2024-05-15
 */
@Service
public class PurchaseOrderServiceImpl extends ServiceImpl<PurchaseOrderMapper, PurchaseOrder> implements IPurchaseOrderService {

    @Autowired
    private PurchaseOrderMapper purchaseOrderService;

    @Override
    public List<PurchaseOrder> purchaseOrderList() {
        return purchaseOrderService.purchaseOrderList();
    }
    @Autowired
    private IPurchaseOrderDetailsService purchaseOrderDetailsService;
    @Autowired
    private PurchaseOrderMapper purchaseOrderMapper;

    //获取采购单中id最大的设计单的编号
    @Override
    public String getMaxDesignId() {
        PurchaseOrder purchaseOrder = purchaseOrderMapper.queryMaxPurchaseOrder();
        if(purchaseOrder == null) {
            return null;
        }
        // 获取采购单编号
        String designId = purchaseOrder.getPurchaseOrderNumber();
        return designId;
    }


    @Override
    public void makePurchaseOrder(List<MakePurchaseDto> makePurchaseDto){


    }

    //查询所有的采购单
    @Override
    public PageUtils<PurchaseOrder> searchAll(int pageNo, int pageSize) {

        PageHelper.startPage(pageNo, pageSize);
        List<PurchaseOrder> list = this.list();
        PageInfo<PurchaseOrder> pageInfo = new PageInfo<>(list);
        // PageInfo 转换成 PageUtils
        PageUtils<PurchaseOrder> pageUtils = new PageUtils<>();
        pageUtils.setRows(pageInfo.getList());
        pageUtils.setTotal(pageInfo.getTotal());

        return pageUtils;

    }
    //查询所有的采购单
    @Override
    public PageUtils<PurchaseOrder> queryAllChecked(int pageNo, int pageSize) {
        QueryWrapper wrapper = new QueryWrapper();
        //审核标志:S001-3（审核通过）
        wrapper.eq("check_tag","S001-3");

        PageHelper.startPage(pageNo, pageSize);
        List<PurchaseOrder> list = this.list(wrapper);
        PageInfo<PurchaseOrder> pageInfo = new PageInfo<>(list);
        // PageInfo 转换成 PageUtils
        PageUtils<PurchaseOrder> pageUtils = new PageUtils<>();
        pageUtils.setRows(pageInfo.getList());
        pageUtils.setTotal(pageInfo.getTotal());

        return pageUtils;

    }
}
